//
//  YAYIServiceContentCell.m
//  YAYIDoctor
//
//  Created by hxp on 16/5/5.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIServiceContentCell.h"

#import "YAYIServiceTagModel.h"


@interface YAYIServiceContentCell()

@property (nonatomic,strong)UILabel *content;
@property (nonatomic,strong)UIButton *selectBtn;
@property (nonatomic,strong)UILabel *seprateLine;
@property (nonatomic,strong)UILabel *vSeprateLine;

@end

@implementation YAYIServiceContentCell


- (void)setModel:(YAYIServiceTagModel *)model
{
    _model = model;
    self.content.text = model.name;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    self.selectBtn.hidden = !selected;
    if (selected) {
        self.content.transform = CGAffineTransformMakeTranslation(4, 0);
    }else{
        self.content.transform = CGAffineTransformMakeTranslation(0, 0);
    }
}


+ (instancetype)cellWith:(UITableView *)tableview
{
    static NSString *cellID = @"serviceContentCell";
    
    YAYIServiceContentCell *cell = [tableview dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYIServiceContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}


-(void)createViews
{
    self.backgroundColor = YAYIColor(239, 239, 239);
    
    self.selectedBackgroundView = [[UIView alloc] init];
    self.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
    
    
    
    if (self.content == nil) {
        self.content = [UILabel new];
        self.content.textColor  = [UIColor colorWithRed:87/255.0 green:85/255.0 blue:85/255.0 alpha:1];
        self.content.font = [UIFont systemFontOfSize:font15];
        [self.contentView addSubview:self.content];
    }
    if (self.selectBtn == nil) {
        self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.selectBtn setImage:[UIImage imageNamed:@"ic_Triangle Copy"] forState:UIControlStateNormal];
        [self.contentView  addSubview:self.selectBtn];
    }
    
    if (self.seprateLine == nil) {
        self.seprateLine = [UILabel new];
        self.seprateLine.backgroundColor = YAYIColor(0xdd, 0xdd, 0xdd);
        [self.contentView addSubview:self.seprateLine];
    }
    
    if (self.vSeprateLine == nil) {
        self.vSeprateLine = [UILabel new];
        self.vSeprateLine.backgroundColor = YAYIColor(0xdd, 0xdd, 0xdd);
        [self.contentView addSubview:self.vSeprateLine];
        [self bringSubviewToFront:self.vSeprateLine];
    }
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(5, 10));
    }];
    
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.selectBtn.mas_left).with.offset(18);
        make.right.equalTo(@10);
        make.height.equalTo(@20);
    }];
    
    [self.seprateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.bottom.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(SCREEN_width, 0.5));
    }];
    
    [self.seprateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.bottom.mas_equalTo(self.contentView).offset(1);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.vSeprateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(0);
        make.top.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView);
        make.width.mas_equalTo(0.5);
    }];
    
    self.selectedBackgroundView.x -= 0.5;
    self.selectedBackgroundView.height -= 1;
}
@end
